package aufgabe2.worker;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class ClientGUI extends JDialog {

	private static final long serialVersionUID = -7475917731054825756L;
	private final JPanel contentPanel = new JPanel();
	private JTextField fieldPort;
	private ArrayList<String> parameters = null;


	public ArrayList<String> showDialog() {
        this.setVisible(true);
        return parameters;

	}

	/**
	 * Create the dialog.
	 */
	public ClientGUI(JFrame parent, String title, boolean modal) {
		super(parent,title,modal);
		setTitle("Parameter");
		
		setBounds(100, 100, 297, 194);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBackground(Color.WHITE);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblTitle = new JLabel("Worker Parameters");
			lblTitle.setBounds(79, 0, 143, 45);
			lblTitle.setFont(new Font("Tahoma", Font.BOLD, 14));
			contentPanel.add(lblTitle);
		}
		
		fieldPort = new JTextField();
		fieldPort.setText("2552");
		fieldPort.setBounds(102, 74, 50, 20);
		contentPanel.add(fieldPort);
		fieldPort.setColumns(10);
		
		JLabel lblPort = new JLabel("Port");
		lblPort.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblPort.setBounds(101, 45, 36, 14);
		contentPanel.add(lblPort);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(Color.WHITE);
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						parameters = new ArrayList<String>();
                        parameters.add(fieldPort.getText());
                        setVisible(false);

					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						setVisible(false);
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
